package cn.dapeng.test.listener;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

public class ApplicationStartedListener implements ApplicationListener<ApplicationStartedEvent> {


    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {

        ConfigurableApplicationContext cxt = event.getApplicationContext();
        System.out.println(cxt.getBeanDefinitionCount());

        Environment environment = cxt.getEnvironment();
        boolean isExist = environment.containsProperty("use-mq.use");

        if(isExist) {
            BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry) cxt.getBeanFactory();

            beanDefinitionRegistry.removeBeanDefinition("studentService");
        }



    }

}
